
var time = require("../../utils/util.js");
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    list: [],
    pageNum: 1,
    pageSize: 10,
    widheight: '',
    total: ''
  },
  onChange(event) {
    var that = this;
    console.log(event)
    that.setData({
      typeindex: event.detail.index,
      pageNum: 1,
    })
    that.setData({
      list: []
    })
    that.list(event.detail.index+1)
  },
  // getdel: function(event){
  //   console.log(event);
  //   if(event.currentTarget.dataset.id != undefined){
  //     wx.navigateTo({
  //       url: '../details/details?orderid=' + event.currentTarget.dataset.id + '&typename=' + event.currentTarget.dataset.typename,
  //     })
  //   }    
  // },
  onGoodsScroll: function(e){
    var that = this;
    console.log(e,that.data.pageNum,Math.ceil(that.data.total/that.data.pageSize),that.data.typeindex);
    if(that.data.pageNum < Math.ceil(that.data.total/that.data.pageSize)){
      that.setData({
        pageNum: that.data.pageNum + 1
      })
      that.list(that.data.typeindex);
    }   
  },
  previewimg(e){
    console.log(e)
    if(e.currentTarget.dataset.img != ""){
      wx.navigateTo({
        url: '../img/img?img=' + e.currentTarget.dataset.img,
      })
    }else{
      wx.showToast({
        title: '该事件暂无图片',
        icon: 'none',
        duration: 2000
      })
    }
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          widheight: res.screenHeight - 130,
          pageSize: Math.ceil((res.screenHeight - 60)/200)
        });
        that.list(1);
      }
    });
  },
  list: function(num){
    var that = this;
    // that.setData({
    //   list: []
    // })
    wx.request({    
      url: time.httpurl + '/event/app/getEventNew?pageNum='  + that.data.pageNum + '&pageSize=' + that.data.pageSize,
      data: {
        eStatus: num,
        personType:"2"
      },
      header: {
        'AppType': '1',
        'Authorization': wx.getStorageSync("token"),
      },
      method: 'POST',
      success: function (res) {
        console.log(res,'list');
        if(res.data.code == 200){
          that.setData({
            list: that.data.list.concat(res.data.rows)
          })
          that.setData({
            total: res.data.total
          })
        }else{
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }     
      }
    })
  },
  task: function(event){
    // console.log(event)
    if(event.currentTarget.dataset.id != undefined){
      wx.navigateTo({
        url: '../worklist/worklist?id=' + event.currentTarget.dataset.id+'&etype=' + event.currentTarget.dataset.etype,
      })
    }
  },
  record: function(event){
    if(event.currentTarget.dataset.id != undefined){
      wx.navigateTo({
        url: '../record/record?id=' + event.currentTarget.dataset.id,
      })
    }
  },
  mappro: function(event){
    if(event.currentTarget.dataset.id != undefined){
      wx.navigateTo({
        url: '../map/map?id=' + event.currentTarget.dataset.id + '&lat=' + event.currentTarget.dataset.lat + '&lng=' + event.currentTarget.dataset.lng,
      })
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
 
  }
})